package com.jd.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jd.shop.dto.OrderDTO;
import com.jd.shop.entity.ShopOrderPO;
import com.jd.shop.mapper.ShopOrderMapper;
import com.jd.shop.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author <a href="https://fengwenyi.com?fs=mpcg">Erwin Feng</a>
 * @since 2023-12-06
 */
@Slf4j
@Service
public class OrderServiceImpl extends ServiceImpl<ShopOrderMapper, ShopOrderPO> implements OrderService {

    @Resource
    private ShopOrderMapper shopOrderMapper;
    @Resource
    private RedissonClient redissonClient;

    /**
     * 秒杀-创建订单
     *
     * @param orderDTO
     */
    @Override
    public void seckill(OrderDTO orderDTO) {
        ShopOrderPO entity = new ShopOrderPO();
        Date date = new Date();
        entity.setCreateTime(date);
        entity.setUpdateTime(date);

        shopOrderMapper.insert(entity);

        redissonClient.getBucket("order", new StringCodec()).set(entity);
    }
}
